from passlib.context import CryptContext

from servies.user import UserServeries

pwd_context = CryptContext(schemes=["bcrypt"],deprecated="auto")

class PasslibHelper:
    # plain_password表示明文密码，hashed_password表示哈希密码
    @staticmethod
    def verity_password(plain_password:str,hashed_password:str):
        """对密码进行校验"""
        return pwd_context.verify(plain_password,hashed_password)

    # 进行哈希密码加密
    @staticmethod
    def hash_password(password:str):
        return pwd_context.hash(password)

if __name__ == "__main__":
    import asyncio
    from db.database import SessionLocal
    from sqlalchemy import func
    async def create_admin_user():
        async with SessionLocal() as session:
            await UserServeries.create_user(
                session,
                username="admin",
                password=PasslibHelper.hash_password("123456"),
                created_at=func.now()
            )
    asyncio.run(create_admin_user())

